<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width,  user-scalable=no">

    <title>改良Ashworth评定</title>

    <style>
        /*.table-a table{border:1px solid #000000}*/

        td {
            vertical-align: bottom;
        }

        #table_guage hr {
            margin: 6.5px auto;
        }

    </style>


</head>

<body>

<div style="font-size: 16px;height: 26px;margin-bottom: 26px;border-bottom: 1px solid #d0d0d0;">
    <label class="print-font16">评定内容</label>
</div>
<div class="hide">
    <table border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td align="left" width="80px"><label style="font-size: 13px;font-weight: bold">陪同者</label></td>
            <td align="left"><input type="text" class="form-control" style="width: 200px" id="text_companion"/></td>
        </tr>
    </table>

</div>

<div class="hide">
    <table border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td align="left" width="80px"><label style="font-size: 13px;font-weight:bold">陪同者</label></td>
            <td align="left"><input type="text" class="form-control" style="width: 200px" id="span_companion"/></td>
        </tr>
    </table>
</div>

<div style="width: 100%;" align="center">
    <form id="form_gauge">
        <!--<table id="table_total" class="view-page table table-bordered hide" style="margin-top: 20px" border="1" cellspacing="0" cellpadding="0">-->
        <!--<tr><td width="40%"  align="center"><label>日常活动 分数总计</label></td><td width="60%"  align="center"><span class="span-total-score"></span></td></tr>-->
        <!--</table>-->

        <div class="table-a">
            <table id="table_guage" border="0" cellspacing="0" cellpadding="0" width="100%">
            </table>
        </div>

        <!--<table id="table_total_edit" class="edit-page table table-bordered hide"  style="margin-top: 20px" border="1" cellspacing="0" cellpadding="0">-->
        <!--<tr><td width="40%"  align="center"><label>日常活动 分数总计</label></td><td width="60%"  align="center"><span class="span-total-score"></span></td></tr>-->
        <!--</table>-->

    </form>
    <div class="edit-page hide" style="margin-top: 20px">
        <div class="col-sm-2"></div>
        <div class="col-sm-4" style="text-align: center">
            <button class="btn btn-white" onclick="resetPage()" type="button" style="width: 102px">重置
            </button>
        </div>
        <div class="col-sm-4" style="text-align: center">
            <button class="btn btn-primary" onclick="submitGaugeResult()" type="button" style="width: 102px">提交
            </button>
        </div>
    </div>
</div>

</body>

<script>

    var totalScore = 0;

    var spanTotalSpan = $(".span-total-score");

    var tableTotalEdit = $("#table_total_edit");
    var tableTotal = $("#table_total");

    var textCompanion = $("#text_companion");
    var spanCompanion = $("#span_companion");

    var editPage = $(".edit-page");
    var viewPage = $(".view-page");

    var gauge_groups = ['上肢痉挛（左）*', '上肢痉挛（右）*', '下肢痉挛（左）*', '下肢痉挛（右）*'];

    var gauge_options = [
        ['屈肘肌群', '屈腕肌群', '屈指肌群']
        ,
        ['屈肘肌群', '屈腕肌群', '屈指肌群']
        ,
        ['小腿三头肌', '腘绳肌', '内收肌']
        ,
        ['小腿三头肌', '腘绳肌', '内收肌']
    ];

    builderQuestion();

    //    initPage();
    //
    //
    //
    //    function initPage() {
    //
    //
    //
    //    }

    function builderQuestion() {
        var index = 1;

        for (var i = 0; i < gauge_groups.length; i++) {
            for (var j = 0; j < gauge_options[i].length; j++) {

                if (j == 0) {
                    //添加组标题
                    var groupTr = "";
                    if (i > 0) {
                        groupTr += "<tr><td  height='26px' class='print-heigh-1'></td></tr>"
                    }
                    groupTr += "<tr><td align='left' ><label style='font-size: 14px;font-weight: bold'>" + gauge_groups[i] + "</label></td></tr>";
                    $("#table_guage").append(groupTr);
                }

                var radio = '<table width="100%"  border="0" cellspacing="0" cellpadding="0">' +
                    '<tr>' +
                    '<td  width="25%"></td>' +
                    '<td  width="15%" align="left"><input type="radio" value="0" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>0级</label></td>' +
                    '<td  width="15%" align="left"><input type="radio" value="1" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>Ⅰ级~Ⅰ+级</label></td>' +
                    '<td  width="15%" align="left"><input type="radio" value="2" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>Ⅱ级</label></td>' +
                    '<td  width="15%" align="left"><input type="radio" value="3" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>Ⅲ级</label></td>' +
                    '<td  width="15%" align="left"><input type="radio" value="4" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>Ⅳ级</label></td>' +
                    '</tr></table>';

                var selectTr = "<tr>" +
                    "<td align='left' style='font-size:13px' id='td_" + i + "_" + j + "'>" + (index++) + " ．" + gauge_options[i][j].trim() + "</td>" +
                    "</tr>" +
                    "<tr><td  id='td_select_" + i + "_" + j + "'>" +
                    "</td></tr>" +
                    "<tr><td height='6.5px' style='border-bottom:1px dashed #d0d0d0;'></td></tr>";
                if (i < gauge_groups.length - 1 || j < gauge_options[i].length - 1) {
                    selectTr += "<tr><td height='6.5px'></td></tr>";
                }
                $("#table_guage").append(selectTr);
                $("#td_select_" + i + "_" + j).append(radio);
            }
        }

//        if(editable==false){
//            $(".question-radio").attr('disabled','disabled');
//        }
    }

    function changeSelect() {

        totalScore = 0;

        for (var i = 0; i < gauge_groups.length; i++) {
            for (var j = 0; j < gauge_options[i].length; j++) {
//                var value=$("#select_" + i + "_" + j).val();
                var value = $("input[name='radio_" + i + "_" + j + "']:checked").val();
                if (typeof(value) == "undefined") {
                    value = 0;
                }
                totalScore += parseInt(value);
            }
        }
        spanTotalSpan.text(totalScore);

    }

    //    function submit(){
    //        changeSelect();
    //        var gauge={};
    //
    //        gauge.total_score=totalScore;
    //
    //        var questions=[];
    //
    //        var index=0;
    //
    //        for (var i = 0; i < gauge_groups.length; i++) {
    //            for (var j = 0; j < gauge_options[i].length; j++) {
    //                var questionKey=$("#td_" + i + "_" + j).html();
    //                questionKey=questionKey.split("．")[1].trim();
    //
    //                var result=$("input[name='radio_" + i + "_" + j+"']:checked").val();
    //                if(typeof(result) == "undefined"){
    //                    result=0;
    //                }
    //                var question={};
    //                question.key=questionKey;
    //                question.value=result;
    //                questions[index++]=question;
    //            }
    //        }
    //
    //        gauge.questions=questions;
    //        gauge.companion=textCompanion.val();
    //        debugAlert(gauge);
    //
    //        mandy_post_gauge_record_result(gaugeRecordId, JSON.stringify(gauge), function (data) {
    //            debugAlert(data);
    //            utils.msgSuccess("提交成功");
    //        });
    //    }

    function setEditable(edit) {


        if (edit == true || edit == 'true') {
            editPage.removeClass('hide');
            viewPage.addClass('hide');
        } else {
//            mandy_get_gauge_record(gaugeRecordId,prcpItemId,function (data) {
//                debugAlert(data.result);
//                var result=eval('('+data.result+')');
//
//                for (var i = 0; i < gauge_groups.length; i++) {
//                    for (var j = 0; j < gauge_options[i].length; j++) {
//                        var questions=result.questions;
//                        for(var k=0;k<questions.length;k++){
//                            if(questions[k].key.trim()==gauge_options[i][j].trim()){
//                                $("input[name='radio_" + i + "_" + j + "']:eq("+questions[k].value+")").attr("checked",'checked');
//                            }
//                        }
//                    }
//                }
//
//                spanTotalSpan.text(result.total_score);
//                spanCompanion.text(result.companion);
//            });
            viewPage.removeClass('hide');
            editPage.addClass('hide');
            $(".question-radio").attr('disabled', 'disabled');
        }

    }

    function setGaugeResult(result) {
//        console.log("result======######>>>>>>",result);
        var questions = result.questions;
        var idx = 0;
        for (var i = 0; i < gauge_groups.length; i++) {
            for (var j = 0; j < gauge_options[i].length; j++) {
//                for (var k = 0; k < questions.length; k++) {
//                    if (questions[k].key.trim() == gauge_options[i][j].trim()) {
//                        $("input[name='radio_" + i + "_" + j + "'][value=" + questions[k].value + "]").attr("checked", 'checked');
//                    }
//                }
                $("input[name='radio_" + i + "_" + j + "'][value=" + questions[idx++].value + "]").attr("checked", 'checked');
            }
        }

        spanTotalSpan.text(result.total_score);
        if (result.companion == null || result.companion == '') {
            spanCompanion.text("无");
        } else {
            spanCompanion.attr("disabled", true);
            spanCompanion.val(result.companion);
        }

    }


    function getGaugeResult() {
        changeSelect();
        var gauge = {};

        gauge.total_score = totalScore;

        var questions = [];

        var index = 0;

//        if(textCompanion.val().trim()==null||textCompanion.val().trim()==''){
//            utils.msgError("请填写陪同者!");
//            return;
//        }

        for (var i = 0; i < gauge_groups.length; i++) {
            for (var j = 0; j < gauge_options[i].length; j++) {
                var questionKey = $("#td_" + i + "_" + j).html();
                questionKey = questionKey.split("．")[1].trim();

                var result = $("input[name='radio_" + i + "_" + j + "']:checked").val();
                if (typeof(result) == "undefined") {
//                    result=0;
                    utils.msgError("第" + (index + 1) + "个选项还未评估!");
                    return;
                }
                var question = {};
                question.key = questionKey;
                question.value = result;
                questions[index++] = question;
            }
        }

        gauge.questions = questions;
        gauge.companion = textCompanion.val();

        spanCompanion.text(gauge.companion);
        debugAlert(gauge);
        return gauge;
    }

    function resetPage() {
        $('#form_gauge').get(0).reset();
    }

</script>

</html>
